package org.eae.eldf.service.base.impl;

import java.util.List;

import org.eae.eldf.dao.base.IBaseLovDao;
import org.eae.eldf.entity.base.BaseLov;
import org.eae.eldf.framework.pager.Pagination;
import org.eae.eldf.framework.persistence.Criteria;
import org.eae.eldf.framework.service.BaseServiceImpl;
import org.eae.eldf.framework.spring.SpringSecurityUtils;
import org.eae.eldf.service.base.BaseLovService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/******************************************************************************
 * @File name : BaseLovServiceImpl.java
 * 
 * @Author : xl
 * 
 * @Date : 2016-6-7
 * 
 * @Copyright Notice: Copyright (c) 2016 Efast Serv. All Rights Reserved. This
 *            software is published under the terms of the Efast Software
 *            License version 1.0, a copy of which has been included with this
 *            distribution in the LICENSE.txt file.
 * 
 * 
 *            ------------------------------------------------------------------
 *            ---------- Date Who Version Comments 2016-6-7 上午10:51:55 xl 1.0
 *            Initial Version
 *****************************************************************************/
@Service
public class BaseLovServiceImpl extends BaseServiceImpl<BaseLov> implements BaseLovService {

	private IBaseLovDao baselovdao;

	@Autowired
	public void setBaselovdao(IBaseLovDao baselovdao) {
		this.baselovdao = baselovdao;
		this.dao = baselovdao;
	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-6-7
	 * @see org.eae.eldf.service.base.BaseLovService#updateBaseLov(org.eae.eldf.entity.base.BaseLov)
	 **/
	@Override
	public void updateBaseLov(BaseLov baseLov) {
		// TODO Auto-generated method stub
		StringBuffer id = new StringBuffer();
		id.append(baseLov.getEnterpriseId() + ".");
		id.append(baseLov.getUserId() + ".");
		id.append(baseLov.getModuleName() + ".");
		id.append(baseLov.getParamKey() + ".");
		id.append(baseLov.getOptionKey() + ".");
		Criteria criteria = Criteria.create(BaseLov.class).set("id", id.toString())
				.set("enterpriseId", baseLov.getEnterpriseId()).set("userId", baseLov.getUserId())
				.set("moduleName", baseLov.getModuleName()).set("paramKey", baseLov.getParamKey())
				.set("i18nParamKey", baseLov.getI18nParamKey()).set("dataType", baseLov.getDataType())
				.set("optionKey", baseLov.getOptionKey()).set("optionOrder", baseLov.getOptionOrder())
				.set("optionDesc", baseLov.getOptionDesc()).set("i18nOptionDesc", baseLov.getI18nOptionDesc())
				.set("parentId", baseLov.getParentId()).set("valid", baseLov.getValid())
				.set("lastUpdateUser", SpringSecurityUtils.getCurrentUserName())
				.where("baseLovId", new Object[] { baseLov.getBaseLovId() });
		
		dao.update(criteria);
	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-6-7
	 * @see org.eae.eldf.service.base.BaseLovService#saveBaseLov(org.eae.eldf.entity.base.BaseLov)
	 **/
	@Override
	public void saveBaseLov(BaseLov baseLov) {
		// TODO Auto-generated method stub
		StringBuffer id = new StringBuffer();
		id.append(baseLov.getEnterpriseId() + ".");
		id.append(baseLov.getUserId() + ".");
		id.append(baseLov.getModuleName() + ".");
		id.append(baseLov.getParamKey() + ".");
		id.append(baseLov.getOptionKey() + ".");
		Criteria criteria = Criteria.create(BaseLov.class).set("id", id.toString())
				.set("enterpriseId", baseLov.getEnterpriseId()).set("userId", baseLov.getUserId())
				.set("moduleName", baseLov.getModuleName()).set("paramKey", baseLov.getParamKey())
				.set("i18nParamKey", baseLov.getI18nParamKey()).set("dataType", baseLov.getDataType())
				.set("optionKey", baseLov.getOptionKey()).set("optionOrder", baseLov.getOptionOrder())
				.set("optionDesc", baseLov.getOptionDesc()).set("i18nOptionDesc", baseLov.getI18nOptionDesc())
				.set("parentId", baseLov.getParentId()).set("valid", baseLov.getValid())
				.set("lastUpdateUser", SpringSecurityUtils.getCurrentUserName())
				.set("createUser", SpringSecurityUtils.getCurrentUserName());
		dao.insert(criteria);
	}

	/**
	 * {@inheritDoc} overridden:
	 * 
	 * @Date : 2016-6-7
	 * @see org.eae.eldf.service.base.BaseLovService#deleteBaseLov(org.eae.eldf.entity.base.BaseLov)
	 **/
	@Override
	public void deleteBaseLov(Long basLovId) {
		// TODO Auto-generated method stub
		dao.delete(BaseLov.class, basLovId);
	}

	/**
	 * {@inheritDoc} 
	 * overridden:
	 * @Date        :      2016-6-7
	 * @see 通过ID查找 该节点下所属lov子节点
	**/
	@Override
	public Pagination<BaseLov> getBaseLovListById(Pagination<BaseLov> pager,Long baseLovId) {
		// TODO Auto-generated method stub
		return baselovdao.getBaseLovListById(pager,baseLovId);
	}

	/**
	 * {@inheritDoc} 
	 * overridden:
	 * @Date        :      2016-6-7
	 * @see org.eae.eldf.service.base.BaseLovService#getBaseLovList()
	**/
	@Override
	public List<BaseLov> getBaseLovListTree() {
		// TODO Auto-generated method stub
		return dao.queryList(Criteria.create(BaseLov.class));
	}

}
